package com.lu.lambda;

import org.junit.Test;

import java.util.Comparator;

/**
 * @author 陆小根
 * date: 2022/07/10
 * Description:
 *
 * Lambda表达式
 */

public class TestLambda01 {

  @Test
  public void test1() {
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        System.out.println("我爱无锡~~");
      }
    };
    r1.run();

    System.out.println("********使用Lambda的写法**************");
    Runnable r2 = () -> System.out.println("我爱盐城~~");
    r2.run();
  }


  @Test
  public void test2() {
    Comparator<Integer> com1 = new Comparator<Integer>() {
      @Override
      public int compare(Integer o1, Integer o2) {
        return Integer.compare(o1, o2);
      }
    };
    int compare1 = com1.compare(12, 21);
    System.out.println(compare1);

    System.out.println("********使用Lambda的写法**************");
    // Lambda 表达式的写法
    Comparator<Integer> com2 = (o1, o2) -> Integer.compare(o1, o2);
    int compare2 = com2.compare(12,1);
    System.out.println(compare2);

    // 方法的应用的写法
    Comparator<Integer> com3 = Integer::compare;
    int compare3 = com3.compare(32,21);
    System.out.println(compare3);
  }

}
